package com.chromatic.messages.model;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;

import java.util.List;

@Entity
@Table(name="competitions_url_list")
public class CompetitionsURL {
    @Id
    @Column(name = "competition_id")
    private int id;
    private String subject;
    private String category;
    private String competition_name;
    private String official_website;
    private String level;
    @Column(columnDefinition = "json")
    private String identified_by;
    private String editor;

    public int getId() {
        return id;
    }

    public String getSubject() {
        return subject;
    }

    public String getCategory() {
        return category;
    }

    public String getCompetition_name() {
        return competition_name;
    }

    public String getOfficial_website() {
        return official_website;
    }

    public String getLevel() {
        return level;
    }

    public List<String> getIdentifiedBy() throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        return objectMapper.readValue(identified_by, new TypeReference<List<String>>() {});
    }

    public String getEditor() {
        return editor;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public void setCompetition_name(String competition_name) {
        this.competition_name = competition_name;
    }

    public void setOfficial_website(String official_website) {
        this.official_website = official_website;
    }

    public void setLevel(String level) {
        this.level = level;
    }

    public void setIdentified_by(List<String> groups) throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        this.identified_by = objectMapper.writeValueAsString(groups);
    }
    public void setEditor(String editor) {
        this.editor = editor;
    }
}
